package model.domain;

import model.algorithm.Heurictics;
import model.algorithm.State;

public class Puzzle8DomainHeuris implements Heurictics {

	@Override
	public double getEvaluation(State current, State goal) {			// Puzzle8DomainHeuris is a type of Heurictics and implements it
		char[] charArray = (current.getState().toCharArray());			// the heuristic function of Puzzle8Domain - calculates the distance
		int sum = 0;													// between each number's position in the "matrix" ("" because its just a String for now)
		for (int i=0; i<=8; i++){										// from its wanted position in the goal State. It sums up all the distances together
			switch (charArray[i]) {										//	and the sum is the value being returned
			case '1':
				sum += i;
				break;
			case '2':
				sum += Math.abs(i-1);
				break;
			case '3':
				sum += Math.abs(i-2);
				break;
			case '4':
				sum += Math.abs(i-3);
				break;
			case '5':
				sum += Math.abs(i-4);
				break;
			case '6':
				sum += Math.abs(i-5);
				break;
			case '7':
				sum += Math.abs(i-6);
				break;
			case '8':
				sum += Math.abs(i-7);
				break;
			case '0':
				break;
			}
		}
		return (double)sum;
	}

}
